<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>回调页面</title>
    <script src="plugins/vue.js"></script>
    <script src="plugins/axios.js"></script>
    <script src="plugins/common.js"></script>
</head>
<body>
    <h1>welcome</h1>
    <div id="myApp">
    </div>
</body>
    <script type="text/javascript">
        new Vue({
            el : '#myApp',
            data : {
                },
            mounted() {
                var url = location.href;
                let obj = parseUrlToJson(url)
                this.$http.post("/login/wxaccount", {'code' : obj.code }).then(res => {
                    if (res.data.success) {
                        alert("登陆成功！");
                        const  {token, loginInfo} = res.data.data;
                        localStorage.setItem("token", token);
                        localStorage.setItem("loginInfo", JSON.stringify(loginInfo));
                        location.href = '/index.html'

                    } else { // 没有绑定用户
                        let access_token = res.data.data.access_token;
                        let openid = res.data.data.openid;
                        location.href = "/binder.html?access_token=" + access_token +
                                "&openid=" + openid;
                    }
                }).catch(
                    res => alert("系统错误")
                );
            }
        });
    </script>
</html>